from PIL import Image
import glob, os

size = 256, 256

imTotal = Image.new("RGBA", size, (0, 0, 0))

print "Enter Filename : "
filename = raw_input()
file, ext = os.path.splitext(filename)

im = Image.open(filename)
imsize = im.size
row = imsize[0] / 256
col = imsize[1] / 256

print imsize
print "row : %d, col : %d\n" % (row, col)

for i in range(row):
    for j in range(col):
#        print "%d %d %d %d\n" %(256*i, 256*(i+1), 256*j, 256*(j+1));
        part = im.crop((256*i, 256*j, 256*(i+1), 256*(j+1)))
        part.load()
        part.save("%s_%d.png" %(file, col*i+j), "PNG")
